import store from '@/store/index.js'
import Tools from '@/utils/Tools.js'
import { CLIENT } from '@/constant/Config.js';
const install = (Vue, vm) => {
	Vue.prototype.$u.uploadFile = (url, args) => {
		return new Promise((resolve, reject) => {
			const token = store.state.user.token
			return uni.uploadFile({
				url,
				...args,
				header: {
					'Authorization': token || ('' + '||' + CLIENT),
				},
				success: (result) => {
					if (result.statusCode == 200) {
						try {
							const resultData = JSON.parse(result.data);
							if (resultData.code == 200) {
								resolve(resultData)
							} else {
								if (resultData.code == 102) {
									//TODO 登录失效
								} else if (resultData.code == 201) {
									uni.showToast({
										icon: 'none',
										title: `错误${resultData.code}：${resultData.msg}`
									})
								} else if (resultData.code = 404) {
									//TODO 需要升级
								}
								reject(resultData)
							}
						} catch (e) {
							reject(e)
						}
					}else{
						reject(result)
						
					}

				},
				fail: (e) => {
					reject(e)
				}

			})
		})
	}
}

export default {
	install
}
